/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
 */

package com.device.idea.demo.view.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.device.idea.demo.R;

/**
 * EraserPopWindow
 * 橡皮擦选择弹出框
 *
 * @since 2020-12-22
 */
public class EraserPickerPopWindow extends BaseToolbarPopupWindow {
    private static final String TAG = EraserPickerPopWindow.class.getSimpleName();

    /**
     * 橡皮擦弹出框子数据
     */
    private OnEraserPickerListener mListener;

    /**
     * 构造方法
     *
     * @param context 上下文对象
     */
    public EraserPickerPopWindow(@NonNull Context context) {
        super(context);
    }

    @NonNull
    @Override
    protected View onCreateContentView(@NonNull Context context) {
        return createPopWindow();
    }

    @Override
    protected String getTag() {
        return TAG;
    }

    /**
     * OnEraserPickerListener
     * 监听
     * 
     * @since 2020-01-01
     */
    public interface OnEraserPickerListener {
        /**
         * onEraserPicker
         *
         * @param eraser eraser
         */
        void onEraserPicker(int eraser);

        /**
         * onEraserClear
         */
        void onEraserClear();
    }

    /**
     * setOnEraserPickerListener
     *
     * @param listener OnEraserPickerListener
     */
    public void setOnEraserPickerListener(OnEraserPickerListener listener) {
        mListener = listener;
    }

    private View createPopWindow() {
        View popWindowView = LayoutInflater.from(mContext).inflate(R.layout.pop_eraser_picker_4k, null);

        TextView cleanTextView = popWindowView.findViewById(R.id.pop_eraser_clean);
        int drawableSize = mContext.getResources().getDimensionPixelSize(R.dimen.dimen_20dp);
        Drawable cleanDrawable = mContext.getResources().getDrawable(R.drawable.wb_tool_eraser, null);
        cleanDrawable.setBounds(0, 0, drawableSize, drawableSize);
        cleanTextView.setCompoundDrawables(cleanDrawable, null, null, null);
        cleanTextView.setSelected(true);

        Drawable clearDrawable = mContext.getResources().getDrawable(R.drawable.wb_tool_screen_clear, null);
        clearDrawable.setBounds(0, 0, drawableSize, drawableSize);

        TextView clearTextView = popWindowView.findViewById(R.id.pop_eraser_clear);
        clearTextView.setCompoundDrawables(clearDrawable, null, null, null);
        clearTextView.setOnClickListener(view -> {
            if (mListener != null) {
                mListener.onEraserClear();
            }
            dismiss();
        });
        return popWindowView;
    }
}